package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.ems.pojo.SystemSvgVO;
import com.econ.powercloud.ems.pojo.requestVO.FileRequestVO;
import com.econ.powercloud.ems.pojo.requestVO.SystemSvgDeleteVO;
import com.econ.powercloud.ems.pojo.requestVO.SystemSvgRequestVO;
import com.econ.powercloud.ems.service.biz.SystemSvgBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jwc
 * @date 2023/05/08
 */
@Api(tags ="svg管理")
@RestController
@RequestMapping(value = "/api/v2/systemSvg")
@RequiredArgsConstructor
public class SystemSvgController extends ApiBaseController{
    private final SystemSvgBizService systemSvgBizService;

    @ApiOperation("新增/修改svg")
    @PutMapping
    public MsgResult<Boolean> update(@RequestBody @Validated SystemSvgRequestVO requestVO) {
        return successHandler(systemSvgBizService.update(requestVO));
    }

    @ApiOperation("删除svg")
    @DeleteMapping("/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "svg的id", required = true, dataType = "Integer")
    })
    public MsgResult<Boolean> delete(@PathVariable("id") Integer id) {
        return successHandler(systemSvgBizService.delete(id));
    }

    @ApiOperation("获取svg详情")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "svg的id", required = true, dataType = "Integer")
    })
    @GetMapping("/{id}")
    public MsgResult<SystemSvgVO> getSvg(@PathVariable("id") Integer id) {
        return successHandler(systemSvgBizService.getSvg(id));
    }

    @ApiOperation("根据条件获取所有svg")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "relationId", value = "关联id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "relationType", value = "关联类型", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "svg类别", required = false, dataType = "Integer"),
    })
    @GetMapping("/getList")
    public MsgResult<List<SystemSvgVO>> getList(@RequestParam(value = "relationId",required = false) String relationId,
                                                @RequestParam(value = "relationType",required = false) String relationType,
                                                @RequestParam(value = "type",required = false) Integer type,
                                                @RequestParam(value = "tag",required = false) String tag) {
        return successHandler(systemSvgBizService.getSvgListByCondition(relationId, relationType, type,tag));
    }

    @ApiOperation("刪除关联id与关联类型下的所有svg")
    @DeleteMapping("/deleteList")
    public MsgResult<Boolean> deleteList(@RequestBody @Validated SystemSvgDeleteVO systemSvgDeleteVO) {
        return successHandler(systemSvgBizService.delete(systemSvgDeleteVO.getRelationId(), systemSvgDeleteVO.getRelationType()));
    }

    @ApiOperation("批量导入svg")
    @PostMapping("batchImportSvg")
    public MsgResult<Boolean> batchImportSvg(@Validated FileRequestVO fileRequestVO){
        return successHandler(systemSvgBizService.batchImportSvg(fileRequestVO));
    }

}
